#! /usr/bin/python
import csv
import math
import os
import time
import matplotlib as mpl
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cbook as cbook


#fig = plt.figure()
#fig2 = plt.figure()
fig3 = plt.figure()
#fig3= plt.figure()

#plot_amp2 = fig.add_subplot(121)
#plot_amp3 = fig.add_subplot(122)
histo_amptrig = fig3.add_subplot(111)


histo_amptrig.set_title("Minimum ch2 voltage: SiPM7")
histo_amptrig.set_xlabel("Min Voltage")
histo_amptrig.set_ylabel("Counts")


x2,y2 = np.loadtxt("Sipm7ch2.csv",delimiter=' ',usecols=(0,1),unpack=True)
cut=[]
for event in y2:
	if event<=(-5*0.00034):
		cut.append(event)
	

#sipm2=analysis(path+dirname)
#sipm2.read_file_list()
#sipm2.set_trigger_threshold(5*0.00034)


#histo_amptrig.hist(cut,50)
#plt.yscale('log', nonposy='clip')
#histo_amptrig.semilogy()
#voltagetime=sipm2.grab_single_waveform(1)

print "mean:",np.mean(cut)
print "err_mean:",np.std(cut)/math.sqrt(float(len(cut)))
print "sigma:",np.std(cut)
print "nentries:",len(cut)

#plt.show()

